#!/usr/bin/env python
#coding=utf8

import httplib, urllib
import MySQLdb
import json

conn= MySQLdb.connect(
        host='192.168.3.10',
        port = 3306,
        user='root',
        passwd='max123',
        db ='kcv',
        )
cur = conn.cursor();

def get_cont():
    httpClient = None
    try:
        params = urllib.urlencode({'secret_key': 'd7772b0674a318d5', 'page': 1})
        headers = {"Content-type": "application/x-www-form-urlencoded"
                        , "Accept": "text/plain"}

        httpClient = httplib.HTTPConnection("diacloud.test", 80, timeout=30)
        httpClient.request("POST", "/api/diamonds", params, headers)

        response = httpClient.getresponse()
        #print response.status    请求返回状态
        #print response.reason    请求结果 OK
        #print response.read()    请求的内容
        #print response.getheaders() #获取头信息

        if(response.status == 200):
            return response.read()
        else:
            return '';
    except Exception, e:
        print e
    finally:
        if httpClient:
            httpClient.close()


def parse_data(data):

getcont = get_cont();
json_str = json.loads(getcont)

print json_str['data'][0]['inscription'];
